import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import dts from 'rollup-plugin-dts';

export default [
  {
    input: 'src/client.js',
    output: [
      {
        file: 'dist/client.js',
        format: 'cjs',
        sourcemap: true,
      },
      {
        file: 'dist/client.mjs',
        format: 'es',
        sourcemap: true,
      },
      {
        file: 'dist/client.umd.js',
        format: 'umd',
        name: 'DataFlareClient',
        sourcemap: true,
        globals: {
          'cross-fetch': 'fetch',
        },
      },
      {
        file: 'dist/client.min.js',
        format: 'umd',
        name: 'DataFlareClient',
        plugins: [terser()],
        sourcemap: true,
        globals: {
          'cross-fetch': 'fetch',
        },
      },
    ],
    plugins: [
      resolve({
        browser: true,
      }),
      commonjs(),
      babel({
        babelHelpers: 'bundled',
        presets: [
          [
            '@babel/preset-env',
            {
              targets: {
                browsers: '> 0.25%, not dead',
                node: '14',
              },
            },
          ],
        ],
      }),
    ],
    external: ['cross-fetch'],
  },
  {
    input: 'src/client.d.ts',
    output: {
      file: 'dist/client.d.ts',
      format: 'es',
    },
    plugins: [dts()],
  },
];
